#!/usr/bin/python3
# -*- coding: utf-8 -*-

'''
重构事件处理器
'''

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication,
                             QWidget)


class Example(QWidget):
    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle("Event Handler")
        self.show()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            self.close()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
